﻿#ifndef FLUTTBLEHELP
#define FLUTTBLEHELP
#include "event_stream_handler.h"
#include <flutter/plugin_registrar_windows.h>
#include <flutter/method_channel.h>
#include <flutter/event_channel.h>
#include <flutter/standard_method_codec.h>
#include <flutter/encodable_value.h>
#include <winrt/Windows.Devices.Bluetooth.h>
#include <winrt/Windows.Devices.Bluetooth.Advertisement.h>
#include <winrt/Windows.Foundation.h>
#include <map>
#include <memory>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace winrt;
using namespace winrt::Windows::Devices::Bluetooth;
using namespace winrt::Windows::Devices::Bluetooth::Advertisement;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::Storage::Streams;
using namespace winrt::Windows::Devices::Radios;
using namespace winrt::Windows::Devices::Bluetooth;
using namespace winrt::Windows::Devices::Bluetooth::Advertisement;
using namespace winrt::Windows::Devices::Bluetooth::GenericAttributeProfile;
using namespace winrt::Windows::Devices::Enumeration;
using flutter::EncodableValue;
using flutter::EncodableMap;
class FlutterBleHelp {
public:
    std::unique_ptr <EventStreamHandler<>> event_paired_handler;
	// 定义回调函数类型
	using SendMessageConnectorCall = std::function<void(const flutter::EncodableValue&)>;
	using LogToFlutterCall = std::function<void(const std::string message)>;
    // 设备监视器
    DeviceWatcher deviceWatcher{ nullptr };
    // 设备监视器事件
    winrt::event_token deviceWatcherAddedToken;
    winrt::event_token deviceWatcherUpdatedToken;
    winrt::event_token deviceWatcherRemovedToken;
    winrt::event_token deviceWatcherEnumerationCompletedToken;
    winrt::event_token deviceWatcherStoppedToken;
	// 构造函数声明
    FlutterBleHelp(SendMessageConnectorCall messageConnectorCall, LogToFlutterCall logToFlutterCall);
    //蓝牙配对 新增
    void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation info);
    //蓝牙配对更新
    void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate info);
    // 蓝牙配对移除
    void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate info);
    // 蓝牙配对已完成
    void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, IInspectable obj);
    // 蓝牙配对结束
    void DeviceWatcher_Stopped(DeviceWatcher sender, IInspectable obj);
    // 蓝牙配对开始
    bool IsDeviceWatcherStarted();
    // 蓝牙配对运行中
    bool IsDeviceWatcherRunning();
    //开始扫描配对设备
    void StastartScanPairedDevices();
    //停止扫描配对设备
    void StopScanPairedDevices();
private:
	// 存储回调函数
	SendMessageConnectorCall messageConnectorCall_;
	LogToFlutterCall logToFlutterCall_;
    bool lookupBooleanProperty(DeviceInformation deviceInfo, param::hstring const& property);
    winrt::hstring lookupStringProperty(DeviceInformation deviceInfo, param::hstring const& property);
};

#endif // FLUTTBLEHELP